﻿using System;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Best.SmartCms.Utility.JsonFormater
{
    /// <inheritdoc />
    public class CustomizeContractResolver : DefaultContractResolver
    {
        protected override string ResolvePropertyName(string propertyName)
        {
            return propertyName.ToLower();
        }

        /// <inheritdoc />
        protected override JsonContract CreateContract(Type objectType)
        {
            var contract = base.CreateContract(objectType);
            if (objectType == typeof(DateTime) || objectType == typeof(DateTime?))
            {
                contract.Converter = new CustomizeDateTimeConverter();
            }

            if (objectType == typeof(Guid) || objectType == typeof(Guid?))
            {
                contract.Converter = new CustomizeGuidConverter();
            }

            return contract;
        }

      
    }

   
}
